<template>
  <div class="xtx-pay-page">
    <div class="container">
      <xtx-bread>
        <xtx-bread-item to="/">首页</xtx-bread-item>
        <xtx-bread-item to="/cart">购物车</xtx-bread-item>
        <xtx-bread-item>支付结果</xtx-bread-item>
      </xtx-bread>
      <!-- 支付结果 -->
      <div class="pay-result" v-if="orderInfo">
        <span v-if="orderInfo?.orderState === 2" class="iconfont icon-queren2 green"></span>
        <span v-else class="iconfont icon-shanchu red"></span>
        <p class="tit">订单支付成功</p>
        <p class="tip">我们将尽快为您发货，收货期间请保持手机畅通</p>
        <p>支付方式：<span>{{ orderInfo.payChannel === 1 ? '支付宝' : '微信' }}支付</span></p>
        <p>支付金额：<span>¥{{ orderInfo.payMoney.toFixed(2)}}</span></p>
        <div class="btn">
          <router-link to="/member"> <xtx-button type="primary" style="margin-right:20px">查看订单</xtx-button></router-link>
          <router-link to="/">
            <xtx-button type="gray">进入首页</xtx-button>
          </router-link>
        </div>
        <p class="alert">
          <span class="iconfont icon-tip"></span>
          温馨提示：小兔鲜儿不会以订单异常、系统升级为由要求您点击任何网址链接进行退款操作，保护资产、谨慎操作。
        </p>
      </div>
    </div>
  </div>
</template>
<script setup>
import { findOrderDetailApi } from '@/api/order'
import { watch, ref } from 'vue'
import { useRoute } from 'vue-router'
import Message from '@/components/library/message'
const route = useRoute()
const orderInfo = ref(null)
// 查询该订单id对应的订单信息
// 侦听订单id的变化
watch(() => route.query.orderId, orderId => {
  if (orderId && route.path === '/member/callback') {
    findOrderDetailApi(orderId).then(data => {
      orderInfo.value = data.result
      console.log(data.result)
    }).catch(err => {
      Message({ type: 'error', text: err.response.data.message })
    })
  }
}, { immediate: true })
</script>
<style scoped lang="less">
.pay-result {
  padding: 100px 0;
  background: #fff;
  text-align: center;

  >.iconfont {
    font-size: 100px;
  }

  .green {
    color: #1dc779;
  }

  .red {
    color: @priceColor;
  }

  .tit {
    font-size: 24px;
  }

  .tip {
    color: #999;
  }

  p {
    line-height: 40px;
    font-size: 16px;
  }

  .btn {
    margin-top: 50px;
  }

  .alert {
    font-size: 12px;
    color: #999;
    margin-top: 50px;
  }
}
</style>